document.addEventListener('DOMContentLoaded', function() {
    let quoteEle = document.querySelector('#quote');
    // 设置文本
    async function setQuote() {
        try {
            fetch('https://v1.hitokoto.cn?c=d&c=i')
                .then((res) => {
                    if (res.ok) {
                        return res.json();
                    } else {
                        console.log('error');
                    }
                })
                .then((data) => {
                    quoteEle.innerText = data.hitokoto;
                    console.log('%c' + 'Success', 'color: #16982b', data);
                })
                .catch((err) => {
                    console.log(err);
                })
        } catch (error) {
            console.log(error);
        }
    }
    // 设置背景
    async function setImage() {
        try {
            fetch('https://api.xygeng.cn/Bing/url')
                .then((res) => {
                    if (res.ok) {
                        return res.json();
                    } else {
                        console.log('error');
                    }
                })
                .then((data) => {
                    document.body.style.backgroundImage = `url(${data.data})`;
                    console.log('%c' + 'Success', 'color: #16982b', data);
                })
                .catch((err) => {
                    console.log(err);
                })
        } catch (error) {
            console.log(error);
        }
    }
    async function callAsync() {
        const quotePromise = setQuote();
        const imagePromise = setImage();

        await quotePromise;
        await imagePromise;
    }
    callAsync()
})